package com.geekweb.common;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.HashMap;
import java.util.Map;

public class RmiServiceHolder {
	private static Map<String, Remote> rmiHolder = new HashMap<String, Remote>();;

	public RmiServiceHolder() {
	}

	public static Remote getRemoteService(String rmiUrl) {
		if (rmiHolder.containsKey(rmiUrl)) {
			return rmiHolder.get(rmiUrl);
		} else {
			try {
				Remote oRemote = Naming.lookup(rmiUrl);
				if (oRemote != null) {
					rmiHolder.put(rmiUrl, oRemote);
					return oRemote;
				}
			} catch (MalformedURLException e) {
				e.printStackTrace();
			} catch (RemoteException e) {
				e.printStackTrace();
			} catch (NotBoundException e) {
				e.printStackTrace();
			}
		}
		return null;
	}
}
